import { ObjectType, Field, Int } from '@nestjs/graphql';
import { Document } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { CommonSchema } from 'src/common/mongodb/commonSchema';
import { Role } from 'src/system/role/entities/role.entity';

@ObjectType({ description: '后台管理用户数据' })
@Schema({ collection: 'UserData' })
export class User extends CommonSchema {
  @Field(() => String)
  @Prop()
  name: string;

  @Field(() => String)
  @Prop()
  username: string;

  @Field(() => String, { nullable: true })
  @Prop()
  avatar: string;

  @Field(() => Int, { nullable: true })
  @Prop()
  gender: number;

  @Field(() => String)
  @Prop({ unique: true })
  email: string;

  @Field(() => String)
  @Prop()
  password: string;

  @Field(() => String, { nullable: true })
  @Prop()
  address: string;

  @Field(() => Role, { nullable: true })
  @Prop({ type: String, ref: 'Role', nullable: true })
  role: number;
}

export type UserDocument = User & Document;
export const UserSchema = SchemaFactory.createForClass(User);
